<?php /*a:1:{s:62:"/www/wwwroot/mod1.idhx.top/tp/view/admin/system/menu_list.html";i:1711067065;}*/ ?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>menu</title>
    <link rel="stylesheet" href="/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuimini/css/public.css" media="all">
    <style>
        .layui-btn:not(.layui-btn-lg):not(.layui-btn-sm):not(.layui-btn-xs) {
            height: 34px;
            line-height: 34px;
            padding: 0 8px;
        }
    </style>
</head>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <div>
                <script type="text/html" id="toolbarDemo">
                    <div class="layui-btn-container">
                        <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
                        <!-- <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button> -->
                    </div>
                </script>
                <table id="demoTreeTb" class="layui-table" lay-filter="demoTreeTb"></table>
            </div>
        </div>
    </div>
    <!-- 操作列 -->
    <script type="text/html" id="auth-state">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

    <script src="/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="/layuimini/js/lay-config.js?1" charset="utf-8"></script>
    <script>
        layui.use(['table', 'treeTable'], function () {
            var $ = layui.jquery;
            var table = layui.table;
            var treeTable = layui.treeTable;

            // 渲染表格
            layer.load(2);

            var insTb = treeTable.render({
                elem: '#demoTreeTb',
                url: 'menuList',
                even:true,
                toolbar: '#toolbarDemo',
                // toolbar: 'default',
                // height: 'full-200',
                tree: {
                    iconIndex: 1,
                    isPidData: true,
                    idName: 'id',
                    openName:'',
                    pidName: 'pid'
                },
                // defaultToolbar: ['filter', 'print', 'exports', {
                //     title: '提示',
                //     layEvent: 'LAYTABLE_TIPS',
                //     icon: 'layui-icon-tips'
                // }],
                cols: [[
                    { type: 'numbers' },
                    { field: 'title', minWidth: 200, title: '权限名称' },
                    // {
                    //     field: 'icon', title: '权限标识', templet: function (d) {
                    //         return '<i class="fa ' + d.icon + '"></i>'
                    //     }
                    // },
                    { field: 'href', title: '菜单路由' },
                    { field: 'desc',   title: '备注' },
                    { field: 'sort', width: 80, align: 'center', title: '排序' },
                    {
                        field: 'isMenu', width: 80, align: 'center', templet: function (d) {
                            if (d.isMenu == 1) {
                                return '<span class="layui-badge layui-bg-gray">按钮</span>';
                            }
                            if (d.parentId == -1) {
                                return '<span class="layui-badge layui-bg-blue">目录</span>';
                            } else {
                                return '<span class="layui-badge-rim">菜单</span>';
                            }
                        }, title: '类型'
                    },
                    { templet: '#auth-state', width: 120, align: 'center', title: '操作' }
                ]],
                style: 'margin-top:0;',
                done: function () {
                    layer.closeAll('loading');
                    insTb.expandAll();//展开所有
                }
            });
            
            /**
            * toolbar监听事件
            */
            treeTable.on('toolbar(demoTreeTb)', function (obj) {
                if (obj.event === 'add') {  // 监听添加操作
                    var index = layer.open({
                        title: '添加权限',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['600px', '600px'],
                        content: 'saveMenu',
                        end: function () {
                            insTb.reload();
                        }
                    });

                    // $(window).on("resize", function () {
                    //     layer.full(index);
                    // });
                } else if (obj.event === 'delete') {  // 监听删除操作
                    var checkStatus = table.checkStatus('currentTableId')
                        , data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                }
            });

            //监听工具条
            treeTable.on('tool(demoTreeTb)', function (obj) {
                var data = obj.data;
                var layEvent = obj.event;
                if (layEvent === 'del') {
                    var id = data.id
                    layer.msg('确定删除此权限', {
                        time: 10000, //10s后自动关闭
                        btn: ['确定', '取消'],
                        btn1: function () {
                            $.ajax({
                                type: "post",
                                url: "delMenu",
                                data: { id: id },
                                dataType: "json",
                                success: function (res) {
                                    layer.msg(res.msg)
                                    if (res.code == 1) {
                                        insTb.reload();
                                    }
                                }
                            });
                        },


                    });

                } else if (layEvent === 'edit') {
                    var index = layer.open({
                        title: '修改权限',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['600px', '600px'],
                        content: 'editMenu?id=' + data.id,
                        end: function () {
                            insTb.reload();
                        }
                    });
                }
            });
        });
    </script>
</body>

</html>